/**
 * 发布评论
 */

const { db, query } = require("../../db/db");
const util = require("util");
const moment = require("moment");

async function PostComment(req, res) {
  const CreateUserId = Number(req.params.username);
  const CreateTime = moment().format("YYYY-MM-DD HH:mm:ss");
  const CommentContent = req.body.CommentContent;
  const ArticleId = req.body.ArticleId || null;
  const FatherCommentId = req.body.FatherCommentId || null;
  const AtUserId = req.body.AtUserId || null;

  const sql_comment = util.format(
    'Insert INTO Comment (CreateUserId,CreateTime,CommentContent,ArticleId,FatherCommentId,AtUserId) \
    Values(%s,"%s","%s",%s,%s,%s)',
    CreateUserId,
    CreateTime,
    CommentContent,
    ArticleId,
    FatherCommentId,
    AtUserId
  );

  await query(sql_comment);

  res.send({
    status: 0,
  });
}

module.exports = { PostComment };
